﻿using MediatR;
using T_Material.API.Application.Commands.RequisitionCommand;
using T_Material.Domain;
using T_Material.Infrastructure;
using T_Material.Infrastructure.ImpI;
using T_Material.Infrastructure.Interface;

namespace T_Material.API.Application.CommandHandlers.RequisitionHandlers
{
    public class RequisitionCreatedCommandHandler : IRequestHandler<RequisitionCreatedCommand, int>
    {
        private readonly IRequisitionRepository requisitionRepository;
        public RequisitionCreatedCommandHandler(IRequisitionRepository requisitionRepository)
        {
            this.requisitionRepository = requisitionRepository;
        }
        public async Task<int> Handle(RequisitionCreatedCommand request, CancellationToken cancellationToken)
        {
            var info = new Requisition();
            info.Id = request.Id;
            info.Title = request.Title;
            info.Recipient = "赵六";
            info.Remarks = request.Remarks;
            info.RequisitionDate = DateTime.Now;
            info.UsageDescription = request.UsageDescription;
            info.ApprovedBy = request.ApprovedBy;
            info.CollectingItems = request.CollectingItems;
            info.GoodsName = request.GoodsName;
            info.TypeName = request.TypeName;
            info.Description = request.Description;
            info.Specifications = request.Specifications;
            info.Country = request.Country;
            info.Province = request.Province;
            info.WarehouseCount = request.WarehouseCount;
            info.ReceivedCount = request.ReceivedCount;
            info.AuditState = 0;
            info.CreateBy = "张三";
            info.CreateDate = DateTime.Now;
            info.UpdateBy = "";
            info.UpdateDate = null;
            info.IsDel = false;
            var res = await requisitionRepository.Addsync(info);
            return res;
        }
    }
}
